package com.itbaizhan.openhis.controller.system;


import com.itbaizhan.openhis.dto.RegisteredItemDto;
import com.itbaizhan.openhis.service.RegisteredItemService;
import com.itbaizhan.openhis.utils.ShiroSecurityUtils;
import com.itbaizhan.openhis.vo.AjaxResult;
import com.itbaizhan.openhis.vo.DataGridView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

//挂号费用设置
@RestController
@RequestMapping("system/registeredItem")
public class RegisteredItemController {
    @Autowired
    private RegisteredItemService registeredItemService;

    /**
     * 分页查询
     * @param registeredItemDto
     * @return
     */
    @GetMapping("listRegisteredItemForPage")
    public AjaxResult listRegisteredItemForPage(RegisteredItemDto registeredItemDto){
        DataGridView dataGridView = registeredItemService.listRegisteredItemForPage(registeredItemDto);
        return AjaxResult.success("查询成功",dataGridView.getData(),dataGridView.getTotal());

    }

    /**
     * 新增挂号费用
     * @param registeredItemDto
     * @return
     */
    @PostMapping("addRegisteredItem")
    public AjaxResult addRegisteredItem(@Validated RegisteredItemDto registeredItemDto){
        registeredItemDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(registeredItemService.addRegisteredItem(registeredItemDto));
    }

    /**
     * 修改
     * @param registeredItemDto
     * @return
     */
    @PutMapping("updateRegisteredItem")
    public AjaxResult updateRegisteredItem(@Validated RegisteredItemDto registeredItemDto){
        registeredItemDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(registeredItemService.updateRegisteredItem(registeredItemDto));
    }

    /**
     * 根据挂号id查询挂号费用
     * @param registeredItemId
     * @return
     */
    @GetMapping("getRegisteredItemById/{registeredItemId}")
    public AjaxResult getRegisteredItemById(@PathVariable @Validated
                                            @NotNull(message = "挂号项目id不能为空") Long registeredItemId){
        return AjaxResult.success("查询成功",registeredItemService.getOne(registeredItemId));
    }

    /**
     * 删除挂号费用设置
     * @param registeredItemByIds
     * @return
     */
    @DeleteMapping("deleteRegisteredItemByIds/{registeredItemByIds}")
    public AjaxResult deleteRegisteredItemByIds(@PathVariable @Validated
                                            @NotNull(message = "挂号项目id不能为空") Long[] registeredItemByIds){
        return AjaxResult.toAjax(registeredItemService.deleteRegisteredItemByIds(registeredItemByIds));
    }
}
